<template>
  <div class="logininput">
      <input
        class="iphone"
        v-model="iphone"
        type="number"
        placeholder="请输入手机号"
        onKeypress="return(/[\d]/.test(String.fromCharCode(event.keyCode)))"
      />
      <input
        class="paddword"
        v-model="password"
        type="password"
        placeholder="请输入密码"
      />
      <button class="submit" @click="submit">登录</button>
    </div>
</template>

<script>
export default {
  name: 'logininput',
  data() {
    return {
        iphone: "",
        password: "",
    };
  },
  created(){
    console.log(process.env)
  },
  methods: {
    submit() {
      let that = this;
      let { iphone, password } = that;
      if (iphone && password) {
        this.axios({
          url: "/login",
          method: "POST",
          params: {
            password,
            phone: iphone,
          },
        }).then((response) => {
          console.log(response.data);
          if(response.data.code == 2001){
            let millisecond = new Date().getTime();
            let expires = new Date(millisecond + 60 * 1000 * 30);
            that.$store.state.token = response?.data?.data?.jwt_token
            document.cookie = 'userInfo' + "=" + JSON.stringify(response?.data?.data) + ";expires=" + expires + ";path=/";
            document.cookie = 'token' + "=" + JSON.stringify(response?.data?.data?.jwt_token) + ";expires=" + expires + ";path=/";
            document.cookie = 'openid' + "=" + JSON.stringify(response?.data?.data?.openid) + ";expires=" + expires + ";path=/";
            this.$router.replace('/')
          }else{
            alert(response.data.msg)
          }
          
        });
      }
    },
  },
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="stylus">

</style>
